package com.pl.service.impl;

import com.pl.dao.FaultMaintenanceDao;
import com.pl.entity.FaultMaintenance;
import com.pl.service.FaultMaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * (FaultMaintenance)表服务实现类
 *
 * @author makejava
 * @since 2024-05-03 14:38:08
 */
@Service
public class FaultMaintenanceServiceImpl implements FaultMaintenanceService {
    @Autowired
    private FaultMaintenanceDao faultMaintenanceDao;

    /**
     * 通过ID查询单条数据
     *
     * @param deviceId 主键
     * @return 实例对象
     */
    @Override
    public FaultMaintenance queryById(Integer deviceId) {
        return this.faultMaintenanceDao.queryById(deviceId);
    }

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @Override
    public List<FaultMaintenance> queryByPage(Integer pageNum) {
        return this.faultMaintenanceDao.queryAllByLimit();
    }

    /**
     * 新增数据
     *
     * @param faultMaintenance 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(FaultMaintenance faultMaintenance, HttpSession session) {
//        FaultMaintenance device = (FaultMaintenance) session.getAttribute("device");
//
////        faultMaintenance.setDeviceName(device.getDeviceName());
////        faultMaintenance.setDeviceCall(new Date());
        faultMaintenance.setDeviceRep(new Date());

        int num = this.faultMaintenanceDao.insert(faultMaintenance);

        if (num>0){
            return true;
        }

        return false;
    }



    /**
     * 修改数据
     *
     * @param faultMaintenance 实例对象
     * @return 实例对象
     */
    @Override
    public FaultMaintenance update(FaultMaintenance faultMaintenance) {
        this.faultMaintenanceDao.update(faultMaintenance);
        return this.queryById(faultMaintenance.getDeviceId());
    }

    /**
     * 通过主键删除数据
     *
     * @param deviceId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer deviceId) {
        return this.faultMaintenanceDao.deleteById(deviceId) > 0;
    }

    @Override
    public List<FaultMaintenance> queryByPageCondition(Map<String, Object> map) {
        return faultMaintenanceDao.selectByPageCondition(map);
    }
}
